<!DOCTYPE html>
<html lang="zh">
<head>
  <#assign title="定时任务管理">
  <#include "/head.html">
</head>
  
<body>
<div class="container-fluid p-t-15">
  
  <div class="row">
    
    <div class="col-lg-12">
      <div class="card">
      
        <div class="card-toolbar clearfix">
          <form id="searchForm" class="form-inline" action="#!" method="post">
            <div class="form-group mb-2 mr-2">
              <input class="form-control" type="text" name="jobName" placeholder="任务名称..">
            </div>
            <div class="form-group mb-2 mr-2">
              <select id="status" name="status" class="form-control">
                <option value="">不限状态</option>
              </select>
            </div>
            <a class="btn btn-default mb-2 mr-2" type="button" onclick="refreshTable()"><i class="mdi mdi-magnify"></i> 搜索</a>
            <button class="btn btn-secondary mb-2" type="reset">重置</button>
          </form>
        </div>
      
        <div class="card-body">
        
          <div id="toolbar" class="toolbar-btn-action">
            <button id="btn_add" type="button" class="btn btn-primary m-r-5" onclick="add('新增定时任务')">
              <span class="mdi mdi-plus" aria-hidden="true"></span>新增
            </button>
            <button id="btn_log" type="button" class="btn btn-info m-r-5" onclick="log()">
              <span class="mdi mdi-view-list" aria-hidden="true"></span>执行日志
            </button>
          </div>
          
          <table id="bootstrap-table"></table>
          
        </div>
      </div>
    </div>
    
  </div>
  
</div>

<#include "/footer.html">

<script type="text/javascript">
var prefix = "system/job";
var listUrl = prefix + '/list';

listDictOptions('sys_job_status', '#status');

bootstrapTable({
	url: listUrl,
    columns: [{
        field: 'id',
        title: '编号'
    }, {
        field: 'jobName',
        title: '任务名称'
    }, {
        field: 'jobClass',
        title: '任务执行类'
    }, {
        field: 'cronExpression',
        title: '运行时间表达式'
    }, {
    	field: 'status',
        title: '状态',
        formatter: function (value, row, index) {
            if (value == 0) {
                is_checked = '';
            } else if (value == 1){
                is_checked = 'checked="checked"';
            }
            var result = '<div class="custom-control custom-switch"><input type="checkbox" class="custom-control-input" id="customSwitch'+ row.id +'" '+ is_checked +'><label class="custom-control-label" for="customSwitch'+ row.id +'" onClick="updateStatus('+ row.id +', '+ value +')"></label></div>';
        
            return result;
        },
    }, {
        field: 'gmtCreate',
        title: '创建时间'
    }, {
    	field: 'operate',
        title: '操作',
        formatter: btnGroup,  // 自定义方法
        events: {
            'click .edit-btn': function (event, value, row, index) {
            	update(row.id, '编辑定时任务');
            },
            'click .runOnce-btn': function (event, value, row, index) {
            	runOnce(row.id);
            },
            'click .delete-btn': function (event, value, row, index) {
            	del(row.id);
            }
        }
    }]
});

//操作按钮
function btnGroup() {
	return [
        '<a type="button" class="edit-btn btn btn-xs btn-default m-r-5" title="修改" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></a>',
        '<a type="button" class="runOnce-btn btn btn-xs btn-default m-r-5" title="运行一次" data-toggle="tooltip"><i class="mdi mdi-repeat-once"></i></a>',
        '<a type="button" class="delete-btn btn btn-xs btn-default" title="删除" data-toggle="tooltip"><i class="mdi mdi-delete"></i></a>'
    ].join('');
}

function runOnce(id) {
	ajaxPost({ 
		url: prefix + '/runOnce/' + id
	});
}

function log() {
	parent.$(parent.document).data('multitabs').create({
        iframe : true,
        title : '定时任务日志',
        url : prefix + '/log'
    }, true);
}
</script>
</body>
</html>